package cn.doctorpda.conference.presenter;

import com.google.gson.reflect.TypeToken;

import java.util.List;

import cn.doctorpda.conference.bean.Entity;
import cn.doctorpda.conference.bean.Msg;
import cn.doctorpda.conference.bean.meeting.AdInfo;
import cn.doctorpda.conference.config.NetConfig;
import cn.doctorpda.conference.model.GetAdModel;
import cn.doctorpda.conference.model.IPostModel;
import cn.doctorpda.conference.okhttp.callback.StringCallback;
import cn.doctorpda.conference.okhttp.https.GetUrl;
import cn.doctorpda.conference.utils.GsonUtil;
import cn.doctorpda.conference.utils.L;
import cn.doctorpda.conference.view.callbackview.IAdView;
import cn.doctorpda.conference.view.callbackview.IBaseView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/24.
 */
public class AdPresenter {
    private IAdView baseView;
    private IPostModel model;

    public AdPresenter(IAdView baseView) {
        this.baseView = baseView;
        model = new GetAdModel();
    }

    public void getAd() {
        model.postNetWorkStringData(GetUrl.appendClientInfo(NetConfig.GET_AD) + "&code=yihuitong_index_turn&site_id=2", new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
                L.i("轮播图gg");
            }

            @Override
            public void onResponse(String response) {
                L.i("轮播图gg",response);
                try {
                    List<AdInfo> info = GsonUtil.fromJson(response, new TypeToken<List<AdInfo>>() {
                    });
                    baseView.adResult(info.get(0));
                    L.i("轮播图",info.get(0).getContents().get(0).getHref_url());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
